package no.hig.ekm.ircclient;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Class representing a network in the connection-dialog class.
 * 
 * @author kristofers
 */
public class Network implements Serializable{
	private static final long serialVersionUID = 2L;
	
	private String name;
	private ArrayList<Server> servers = new ArrayList<Server>();
	
	/**
	 *	Default Constructor
	 */
	public Network() {
		this.name = "";
		this.servers = null;
	}
	
	/**
	 * Basic constructor, providing a name
	 * 
	 * @param name - The network-name
	 */
	Network(String name) {
		this.name = name;
	}
	
	/**
	 * Constructor providing both a name of the network, and a list of
	 * servers belonging to it.
	 * 
	 * @param name - Networkname
	 * @param servers - List of servers
	 */
	public Network(String name, ArrayList<Server> servers) {
		//super();
		this.name = name;
		this.servers = servers;
	}
	
	/**
	 * @return the servers
	 */
	public ArrayList<Server> getServers() {
		return servers;
	}

	/**
	 * Removes a server from the list.
	 * 
	 * @param sName
	 * @return
	 */
	public boolean removeServer (String sName) {
		int i = 0;
		for (Server serv : servers) {
			//If the server has been found - remove it
			if (!serv.equals(null) && serv.getName().equalsIgnoreCase(sName)) {
				servers.remove(i);
				return true;
			}
			i++;
		}
		return false;
	}
	
	/**
	 * Returns an bool, stating if it have servers (true) or not (false)
	 * 
	 * @return a bool.
	 */
	public boolean hasServers() {
		if (servers.isEmpty())
			return false;
		else
			return true;
	}

	/**
	 * Add a single server.
	 * 
	 * @param name - A name of the server
	 * @param address - The IP/Hostname of the server
	 * @param ports - Which ports does the IRC-server reside?
	 */
	void addServer(String name, String address, String ports) {
		servers.add(new Server(name, address, ports));
	}
	
	/**
	 * Adds a new list of servers.
	 * 
	 * @param serv - ArrayList containing the servers
	 */
	void addServers(ArrayList<Server> serv) {
		servers = serv;
	}
	
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
}
